function addWorkHistory( ){
		$('#workHistories > tbody > tr:last-child')
		.after('<tr>'
			+'<td><input type="text" class="x-text x-date" name="work_date_from[]" onclick="date_picker(this,{noTime:true})" value=""></td>'
			+"<td><input type='text' class='x-text x-date' name='work_date_to[]' onclick='date_picker(this,{noTime:true})' value=''></td>"
			+"<td align='center'><input type='text' class='x-text' name='work_company[]'></td>"
			+"<td align='center'><input type='text' style='width:550px;' class='x-text' name='work_wnotes[]'></td>"
			+"<td align='center'><a title='Xóa' onclick='$(this.parentNode.parentNode).remove()'><b>[ - ]</b></a></td>"
		+'</tr>');	
}

function addTrainee(){
       var str ="";
       for( var i=0;i < DEG_TRANNING.length;i++){
            str +="<option value='"+DEG_TRANNING[i].ID+"'>"+DEG_TRANNING[i].title+"</option>";
        }

		$('#Trainee > tbody > tr:last-child')
			.after('<tr>'
				+'<td><input type="text" class="x-text x-date" name="train_date_from[]" onclick="date_picker(this,{noTime:true})" value=""></td>'
				+'<td><input type="text" class="x-text x-date" name="train_date_to[]" onclick="date_picker(this,{noTime:true})" value=""></td>'
				+'<td><input type="text" style="width:196px" class="x-text" name="train_at[]"></td>'
				+'<td><select class="x-select skills" style="width:150px" name="train_level[]">'
					+'<option value="" selected></option>'
					+ str
					+ '</select></td>'
				+'<td><select class="x-select" style="width:120px" name="train_level_type[]">'
					+'<option value=""></option>'
					+'<option value="Xuất sắc">Xuất sắc</option>'
					+'<option value="Giỏi">Giỏi</option>'
					+'<option value="Khá">Khá</option>'
					+'<option value="Trung bình">Trung bình</option>'
					+'<option value="Yếu kém">Yếu kém</option>'
                +'</select></td>'
				
				+"<td><input type='text' style='width:230px;' class='x-text' name='train_desc[]'></td>"
				+"<td align='center'><a title='Xóa' onclick='$(this.parentNode.parentNode).remove()'><b>[ - ]</b></a></td>"
			+'</tr>');	
}

function addContract(){
       var str ="";
       for( var i=0;i < CONTRACT_TYPES.length;i++){
            str +="<option value='"+CONTRACT_TYPES[i].ID+"'>"+CONTRACT_TYPES[i].title+"</option>";
        }

		$('#tbContract > tbody > tr:last-child')
			.after('<tr>'
				+'<td align="center"><input type="text" style="width:200px;" class="x-text" name="contract_title[]"></td>'
				+'<td align="center"><input type="text" style="width:80px;" class="x-text" name="contract_code[]"></td>'
				+'<td align="center"><select class="x-select skills" style="width:150px" name="contract_type_id[]">'
					+ str
					+ '</select></td>'	
				+'<td align="center"><input type="text" class="x-text x-date" name="contract_date_reg[]" onclick="date_picker(this,{noTime:true})" value=""></td>'
				+'<td align="center"><input type="text" class="x-text x-date" name="contract_date_start[]" onclick="date_picker(this,{noTime:true})" value=""></td>'
				+'<td align="center"><input type="text" class="x-text x-date" name="contract_date_finish[]" onclick="date_picker(this,{noTime:true})" value=""></td>'
				+"<td align='center'><a title='Xóa' onclick='$(this.parentNode.parentNode).remove()'><b>[ - ]</b></a></td>"
			+'</tr>');	
}

function addSHD(){
	$('#workActiveSHD > tbody > tr:last-child')
		.after(
			"<tr>"
			+'<td><input type="text" class="x-text x-date" name="date_govs_from[]" onclick="date_picker(this,{noTime:true})" value=""></td>'
			+"<td><input type='text' class='x-text x-date' name='date_govs_to[]' onclick='date_picker(this,{noTime:true})' value=''></td>"
			+"<td><input type='text' style='width:250px;' class='x-text' name='act_at[]'></td>"
			+"<td><input type='text' style='width:460px;' class='x-text' name='act_desc[]'></td>"
			+"<td align='center' width='100'><a title='Xóa' onclick='$(this.parentNode.parentNode).remove()'><b>[ - ]</b></a></td>"
			+"</tr>");	
}

function addSalaryRow(a){
	$("<tr>"
		+"<td align='center'><input type='text' disabled class='x-text x-date' name='dateup[]' onclick='date_picker(this,{noTime:true})'></td>"//ngày
		+"<td align='center'><select class='x-select' name='skill_id[]'></select></td>"
		+"<td align='center'><select name='countb[]' disabled style='width:60px' class='x-select countb'></select></td>"//bac luong
		+"<td align='center' class='initsalary'></td>"
		+"<td align='center'><select disabled name='plussalary[]' class='x-select plusalary'>"
		+(function(){
			var t="";
			for(var i=0;i<=10;i++)
				t+="<option value='"+(i/10)+"'>"+(i/10)+"</option>";
			return t;	
		})()		
		+"</select></td>"//hệ số phụ
		+"<td class='sum_salary' align='center'></td>"//tong luong
		+"<td align='center'><a title='Xóa' onclick='$(this.parentNode.parentNode).remove()'><b>[ - ]</b></a></td>"
	+"</tr>")
		.afterTo('#salaryTb > tbody > tr:last-child')
		.each(function(){
			var elem = this;
			$(this)
				.find("select[name*=skill_id]")
				.empty("option")
				.each(function(){
					var sillsl = this;
					$("<option></option>")
						.appendTo(this);
					for( var i=0;i < SALARY_PARAMS.length;i++){
						$("<option value='"+SALARY_PARAMS[i].ID+"'>"+SALARY_PARAMS[i].title+"</option>")
							.each(function(){
								this.data = SALARY_PARAMS[i];
							})
							.appendTo(this);
					}	
					
					$(elem)
					.find("select.countb, select.plusalary")
					.onChange(function(){
						var data = sillsl.options[sillsl.selectedIndex].data;
						get_sum_salary( elem,data )
					});
					
				})
				.onChange(function(){
					var data = this.options[this.selectedIndex].data;
					if(!data){
						$(elem)
							.find("select.countb")
							.empty("option")
							.set('disabled',true);
						$(elem)
							.find("input.x-date")
							.set('disabled',true);
						$(elem)
							.find("select.plusalary")
							.set('disabled',true);
						$(elem)
								.find("td.sum_salary")
								.htm('');							
						$(elem)
								.find("td.initsalary")
								.htm('');							
								
						return;
					}
					$(elem)
						.find("select.countb")
						.empty("option")
						.set('disabled',false)
						.each(function(){
							for(var i=0;i < data.countb; i++ ){
								$(this)
									.append("<option value='"+(i+1)+"'>"+(i+1)+"</option>")
							}						
						})
					$(elem)
						.find("input.x-date")
						.set('disabled',false);
					$(elem)
						.find("select.plusalary")
						.set('disabled',false);
					
					get_sum_salary( elem,data );
				});	
		});
}

function get_sum_salary( elem,data ){
	//get sum salary
	var deg = parseFloat($(elem).find("select.countb").get('value'));
	var auxi = parseFloat($(elem).find("select.plusalary").get('value'));
	var param = parseFloat(data['salary']);
	var step = parseFloat(data['subsalary']);
	
	var sum = ( param + step*(deg-1) + auxi )*BASIC_SALARY;
	sum = Math.round(sum);
	var a = sum.toString().split(''),txt='';							
	for(var i = 0 ; i < a.length ; i++ ){
		 txt =((i % 3 == 2 ) ? ',' : '') + a[a.length-1 - i] + txt
	}		
	
	$(elem)
		.find("td.sum_salary")
		.htm( txt );

	$(elem)
			.find("td.initsalary")
			.htm(data.salary);							
		
}

function per_uptext(a){
    a.value = a.value.toString().toUpperCase();
}